#pragma once
#include<iostream>
#include<string>
using namespace std;
//模拟要处理的任务：

string opers="+-*/%";
enum 
{   
    DivZero=1,
    ModZero,
    Unknown
};

class Task 
{
public:
    Task()//提供一个无参默认构造函数，方便我们构造临时的Task对象使用
    {}
    Task(int x,int y,char op):data1_(x),data2_(y),oper_(op),result_(0),exitcode_(0)
    {}
    //执行任务：
    void run()
    {
        switch(oper_)
        {
            case '+':
                result_=data1_+data2_;
                break;
            case '-':
                result_=data1_-data2_;
                break;
            case '*':
                result_=data1_*data2_;
                break;
            case '/':
                {   
                    if(data2_==0)exitcode_=DivZero;
                    else result_=data1_/data2_;
                }
                break;
            case '%':
                {
                   
                    if(data2_==0)exitcode_=ModZero;
                    else result_=data1_%data2_;
                }
                break;
            default:
                exitcode_=Unknown;
                break;
        }
    }

    void operator()()//重载()运算符
    {
        run();
    }
    string GetResult()
    {
        string r=to_string(data1_);
        r+=oper_;
        r+=to_string(data2_);
        r+="=";
        r+=to_string(result_);
        r+="[exitcode:";
        r+=to_string(exitcode_);
        r+="]";
        return r;
    }
    string GetTask()
    {
        string r=to_string(data1_);
        r+=oper_;
        r+=to_string(data2_);
        r+="=?";
        return r;
    }
    ~Task()
    {

    }
private:
    int data1_;
    int data2_;
    char oper_;
    int result_;
    int exitcode_;
};